package com.atguigu.flink.chapter5.transform;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink05_Transform_KeyBy {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);
        DataStreamSource<Integer> source = env.fromElements(1, 1, 20, 20, 100);
        // 如果里面存的是元组, 则可以使用位置 0,...
        source
          .map(new MapFunction<Integer, Tuple2<String, Integer>>() {
              @Override
              public Tuple2<String, Integer> map(Integer value) throws Exception {
                  return Tuple2.of("" + value, value);
              }
          })
          .keyBy(0)
          .sum(1)
          .print();



        env.execute();
    }
}
/*
这些function 都有一个Rich
 */
